using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameFramework.Interfaces;
using Microsoft.Xna.Framework;

namespace GameFramework.Objects
{
    public abstract class ThreePointObject : TransitionObject, IMoveable
    {
        private Vector2 _transitionOnPosition;
        public Vector2 TransitionOnPosition
        {
            get
            {
                return _transitionOnPosition;
            }
            set
            {
                _transitionOnPosition = value;
            }
        }

        private Vector2 _activePosition;
        public Vector2 ActivePosition
        {
            get
            {
                return _activePosition;
            }
            set
            {
                _activePosition = value;
            }
        }

        private Vector2 _transitionOffPosition;
        public Vector2 TransitionOffPosition
        {
            get
            {
                return _transitionOffPosition;
            }
            set
            {
            }
        }

        private Vector2 _position;        
        public Vector2 Position
        {
            get
            {
                return _position;
            }

            set
            {
                OnPositionChange();
                _position = value;
            }
        }

        public ThreePointObject(Game game, Vector2 onPosition, Vector2 acTivePosition, Vector2 offPosition)
            : base(game)
        {
            _transitionOnPosition = onPosition;
            _activePosition = acTivePosition;
            _transitionOffPosition = offPosition;

            _position = _transitionOnPosition;//begin at onPosition
        }

        public ThreePointObject(Game game, Vector2 position) 
            : base(game)
        {
            _transitionOnPosition = position;
            _activePosition = position;
            _transitionOffPosition = position;

            _position = position;
        }

        /// <summary>
        /// For child class that set position after constructor.
        /// </summary>
        /// <param name="game"></param>
        public ThreePointObject(Game game)
            : base(game)
        {

        }

        /// <summary>
        /// Update Position from TransitionOn to Active Position
        /// </summary>
        public override void OnTransitonOn()
        {
            Position = _transitionOnPosition + TransitionAlpha * Vector2.Subtract(_activePosition,_transitionOnPosition);
            base.OnTransitonOn();
        }

        /// <summary>
        /// Set Position by Active Position
        /// </summary>
        public override void EndTransitionOn()
        {
            Position = _activePosition;
            base.EndTransitionOn();
        }

        /// <summary>
        /// Update Position from active position to hidden position
        /// </summary>
        public override void OnTransitionOff()
        {
            Position = _activePosition + TransitionAlpha * Vector2.Subtract(_transitionOffPosition, _activePosition);
            base.OnTransitionOff();
        }

        /// <summary>
        /// position = off position
        /// </summary>
        public override void EndTransitionOff()
        {
            _position = _transitionOffPosition;
            base.EndTransitionOff();
        }

        public override void Reset()
        {
            _position = _transitionOnPosition;
            base.Reset();
        }

        public virtual void OnPositionChange()
        {
        }

        public virtual void Move(float dx, float dy)
        {
            _position.X += dx;
            _position.Y += dy;
        }            
    }
}
